<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('填写加入购物车信息')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-addLoan-add">
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">填写数量：</label>
                <div class="col-sm-8">
                    <input id="number" name="number" class="form-control" type="text" required>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        let cosId = [[${cosId}]];
        let cosmetics = [[${cosmetics}]];
        let prefix = ctx + "admin/cart"

        $(function() {
            $('#number').attr("placeholder",'库存数量'+cosmetics.number);
        });

        $("#form-addLoan-add").validate({
            focusCleanup: true,
            rules: {
                number: {
                    digits: true,
                    min: 1
                },
            },
        });

        function submitHandler() {
            if ($.validate.form()) {
                let number = $('#number').val();
                if(number > cosmetics.number){
                    $.modal.alertWarning("库存不足，请重新填写！");
                    return;
                }
                $.ajax({
                    url:prefix + '/add',
                    type:'post',
                    data:{cosId,number},
                    dataType:'json',
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        $.operate.successTabCallback(result);
                    }
                });
            }
        }
    </script>
</body>
</html>